package com.jxc.dao.impl;

import java.sql.SQLException;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.jxc.dao.PurchaselistDao;
import com.jxc.entity.Purchaselist;
import com.jxc.util.PageBean;

public class PurchaseListDaoImpl extends HibernateDaoSupport implements
		PurchaselistDao {
	private static final Object Purchaselist = null;
	public void insertPurchaseList(Purchaselist purchaselist) {
		this.getHibernateTemplate().save(purchaselist);
	}

	public PageBean getPuchaselistList(final PageBean pb, final String hql) {
		// TODO Auto-generated method stub
		getHibernateTemplate().execute(new HibernateCallback() {
			
			public Object doInHibernate(Session session) throws HibernateException,
					SQLException {
				// TODO Auto-generated method stub
				Query query =session.createQuery(hql);
				pb.setTotalitem(query.list().size());
				query.setFirstResult((pb.getPageon()-1)*pb.getPagesize());
				query.setMaxResults(pb.getPagesize());
				pb.setList(query.list());
				return pb;
			}
		});
		 return pb;
	}
	public void deletePurchaseList(Purchaselist purchaselist) {
		getHibernateTemplate().delete(Purchaselist);
	}
	public void updatePurchaseList(Purchaselist purchaselist) {
		getHibernateTemplate().update(Purchaselist);
	}
	public Purchaselist getpurchaselist(Purchaselist purchaselist) {
		Purchaselist _purchaserlist=(Purchaselist)getHibernateTemplate().get(Purchaselist.class,purchaselist.getId());
		return _purchaserlist;
	}
}
